

package jetbrains.buildServer.server.rest.data.util;

import java.util.function.Function;
import org.jetbrains.annotations.NotNull;

public class UnwrappingFilter<NAKED, WRAPPED> implements ItemFilter<WRAPPED> {
  private final ItemFilter<NAKED> myNakedFilter;
  private final Function<WRAPPED, NAKED> myUnwrapper;

  public UnwrappingFilter(@NotNull ItemFilter<NAKED> nakedFilter, @NotNull Function<WRAPPED, NAKED> unwrapper) {
    myNakedFilter = nakedFilter;
    myUnwrapper = unwrapper;
  }

  @Override
  public boolean isIncluded(@NotNull WRAPPED item) {
    return myNakedFilter.isIncluded(myUnwrapper.apply(item));
  }

  @Override
  public boolean shouldStop(@NotNull WRAPPED item) {
    return myNakedFilter.shouldStop(myUnwrapper.apply(item));
  }
}